package leetcode.code0066;

public class Solution extends Solution0066 {

	/**
	 * 提示： <br>
	 * 1 <= digits.length <= 100 <br>
	 * 0 <= digits[i] <= 9 <br>
	 */
	@Override
	public int[] plusOne(int[] digits) {
		int len = digits.length;
		int num = digits[len - 1] + 1; // 末尾 +1
		int carry = num / 10; // 进位
		digits[len - 1] = num % 10;// 末尾值
		if (carry == 0) {
			return digits; // 没进位, 结束
		} else {
			for (int i = len - 2; i >= 0; i--) {
				num = digits[i] + carry;
				carry = num / 10;
				digits[i] = num % 10;
				if (carry == 0)
					return digits;// 直到没进位, 结束
			}
		}
		int[] ans = new int[len + 1];// 跳出for, 首尾进位, 数组长度+1
		ans[0] = 1;
		for (int i = 0; i < len; i++) {
			ans[i + 1] = digits[i];
		}
		return ans;
	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();

	}

}
